//
//  NSDate+Utilities.h
//
//          日期扩展工具类

#import <Foundation/Foundation.h>
#define D_MINUTE	60
#define D_HOUR	3600
#define D_DAY	86400
#define D_WEEK	604800
#define D_YEAR	31556926
@interface NSDate (Utilities)

+ (NSCalendar *)mt_currentCalendar; // avoid bottlenecks

// Relative dates from the current date
+ (NSDate *)mt_dateTomorrow;
+ (NSDate *)mt_dateYesterday;
+ (NSDate *)mt_dateWithDaysFromNow: (NSInteger) days;
+ (NSDate *)mt_dateWithDaysBeforeNow: (NSInteger) days;
+ (NSDate *)mt_dateWithHoursFromNow: (NSInteger) dHours;
+ (NSDate *)mt_dateWithHoursBeforeNow: (NSInteger) dHours;
+ (NSDate *)mt_dateWithMinutesFromNow: (NSInteger) dMinutes;
+ (NSDate *)mt_dateWithMinutesBeforeNow: (NSInteger) dMinutes;

// Short string utilities
- (NSString *)mt_stringWithDateStyle: (NSDateFormatterStyle) dateStyle timeStyle: (NSDateFormatterStyle) timeStyle;
- (NSString *)mt_stringWithFormat: (NSString *) format;

@property (nonatomic, readonly) NSString *mt_shortString;
@property (nonatomic, readonly) NSString *mt_shortDateString;
@property (nonatomic, readonly) NSString *mt_shortTimeString;
@property (nonatomic, readonly) NSString *mt_mediumString;
@property (nonatomic, readonly) NSString *mt_mediumDateString;
@property (nonatomic, readonly) NSString *mt_mediumTimeString;
@property (nonatomic, readonly) NSString *mt_longString;
@property (nonatomic, readonly) NSString *mt_longDateString;
@property (nonatomic, readonly) NSString *mt_longTimeString;

//string to DataWidthFormatter
+ (NSDate *)mt_dateFromDateStr: (NSString*) date withFormatter:(NSString *) format;

// Comparing dates
- (BOOL)mt_isEqualToDateIgnoringTime: (NSDate *) aDate;

- (BOOL)mt_isToday;
- (BOOL)mt_isTomorrow;
- (BOOL)mt_isYesterday;

- (BOOL)mt_isSameWeekAsDate: (NSDate *) aDate;
- (BOOL)mt_isThisWeek;
- (BOOL)mt_isNextWeek;
- (BOOL)mt_isLastWeek;

- (BOOL)mt_isSameMonthAsDate: (NSDate *) aDate;
- (BOOL)mt_isThisMonth;
- (BOOL)mt_isNextMonth;
- (BOOL)mt_isLastMonth;

- (BOOL)mt_isSameYearAsDate: (NSDate *) aDate;
- (BOOL)mt_isThisYear;
- (BOOL)mt_isNextYear;
- (BOOL)mt_isLastYear;

- (BOOL)mt_isEarlierThanDate: (NSDate *) aDate;
- (BOOL)mt_isLaterThanDate: (NSDate *) aDate;

- (BOOL)mt_isInFuture;
- (BOOL)mt_isInPast;

// Date roles
- (BOOL)mt_isTypicallyWorkday;
- (BOOL)mt_isTypicallyWeekend;

// Adjusting dates 加和减
- (NSDate *) mt_dateByAddingYears: (NSInteger) dYears;
- (NSDate *) mt_dateBySubtractingYears: (NSInteger) dYears;
- (NSDate *) mt_dateByAddingMonths: (NSInteger) dMonths;
- (NSDate *) mt_dateBySubtractingMonths: (NSInteger) dMonths;
- (NSDate *) mt_dateByAddingDays: (NSInteger) dDays;
- (NSDate *) mt_dateBySubtractingDays: (NSInteger) dDays;
- (NSDate *) mt_dateByAddingHours: (NSInteger) dHours;
- (NSDate *) mt_dateBySubtractingHours: (NSInteger) dHours;
- (NSDate *) mt_dateByAddingMinutes: (NSInteger) dMinutes;
- (NSDate *) mt_dateBySubtractingMinutes: (NSInteger) dMinutes;

// Date extremes
- (NSDate *) mt_dateAtStartOfDay;
- (NSDate *) mt_dateAtEndOfDay;

// Retrieving intervals
- (NSInteger) mt_minutesAfterDate: (NSDate *) aDate;
- (NSInteger) mt_minutesBeforeDate: (NSDate *) aDate;
- (NSInteger) mt_hoursAfterDate: (NSDate *) aDate;
- (NSInteger) mt_hoursBeforeDate: (NSDate *) aDate;
- (NSInteger) mt_daysAfterDate: (NSDate *) aDate;
- (NSInteger) mt_daysBeforeDate: (NSDate *) aDate;
- (NSInteger) mt_distanceInDaysToDate:(NSDate *)anotherDate;

// Decomposing dates
@property (readonly) NSInteger mt_nearestHour;
@property (readonly) NSInteger mt_hour;
@property (readonly) NSInteger mt_minute;
@property (readonly) NSInteger mt_seconds;
@property (readonly) NSInteger mt_day;
@property (readonly) NSInteger mt_month;
@property (readonly) NSInteger mt_week;
@property (readonly) NSInteger mt_weekday;
@property (readonly) NSInteger mt_nthWeekday; // e.g. 2nd Tuesday of the month == 2
@property (readonly) NSInteger mt_year;
@end
